package com.jielihaofeng.cachekit;

import java.util.concurrent.ThreadFactory;

/**
 * @author Johnnie Wind
 * @description 线程工厂类
 * @date 2021/10/25 11:57
 */
public class EventThreadFactory implements ThreadFactory {

    private String prefix;
    private boolean threadIsDaemon = true;
    private int threadPriority = Thread.NORM_PRIORITY;

    public EventThreadFactory(String prefix){
        this.prefix = prefix;
    }

    public EventThreadFactory(String prefix,int threadPriority){
        this.prefix = prefix;
        this.threadPriority = threadPriority;
    }

    @Override
    public Thread newThread(Runnable runner) {
        Thread thread = new Thread(runner);
        String name = thread.getName();
        thread.setName(prefix+name);
        thread.setDaemon(threadIsDaemon);
        thread.setPriority(threadPriority);
        return null;
    }
}
